<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
        <el-form-item label="选择状态" >
        <el-select
          v-model="queryParams.type"
          placeholder="请选择"
          clearable
          size="small"
        >
          <el-option
            v-for="(dict,index) in typeSteps"
            :key="index"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" >
        <el-date-picker
          v-model="queryParams.crtTime"
          value-format="yyyy-MM"
          type="month"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
       <el-form-item label="部门名称" >
          <el-select size="small" v-model="queryParams.wnameSJ" placeholder="请选择回收单位" ref="selectReport">
            <el-option :value="queryParams.depId" :label="queryParams.deptName" style="width:199px;height:200px;overflow: auto;background-color:#fff">
              <el-tree
                highlight-current
                 accordion
                :data="reportData"
                :props="defaultProps"
                @node-click="handleNodeClickSJ"
              ></el-tree>
            </el-option>
          </el-select>
      </el-form-item>
        <el-form-item label="物资名称" >
          <el-input
            v-model="queryParams.mName"
            placeholder="请输入物资名称"
            clearable
            size="small"
          />
        </el-form-item>
      <el-form-item>
        <el-button  type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
        <el-button  type="success" icon="el-icon-plus" size="mini" @click="cgjhadd">新增</el-button>
        <el-button  type="warning" icon="el-icon-download" size="mini" @click="dcME">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="日期" property="crtTime" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="回收单位"  property="depName" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="地点" property="place" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="物资名称"  property="mname" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="规格型号"  property="mmodel" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="计量"  property="unit" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="单价"  property="planPrice" :show-overflow-tooltip="true" ></el-table-column>
       <el-table-column align="center" label="数量"  property="demandNumber" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="金额"  property="total" :show-overflow-tooltip="true" >
        <!-- <template slot-scope="scope">
        <span>
          {{(scope.row.demandNumber/1)*(scope.row.planPrice/1)}}
        </span>
        </template> -->
      </el-table-column>
      <el-table-column align="center" label="状态"  property="type" :show-overflow-tooltip="true" >
          <template slot-scope="scope" style="text-align: center">
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.type=='1'">回收</div>
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.type=='2'">复用</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.type=='3'">新品</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.type=='4'">修复</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="备注"  property="remarks" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="400px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="handleXG(scope.row)">修改</el-button>
             <el-button
            size="mini"
            type="danger"
            icon="el-icon-edit"
            @click="handleSC(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />


  </div>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "Role",
    components:{

    },
    data() {
      return {
          //记录分页数据
        localPage:undefined,
        localSize:undefined,
        //修改传参
        xgME:'put',
        //新增传参
        xzME:'post',
        //选择模块
        typeSteps:[
          { value: '',label: '全部'},
          { value: '1',label: '回收'},
          { value: '2',label: '复用'},
          { value: '3',label: '新品'},
          { value: '4',label: '修复'},
        ],
        //战线数据
        reportData:[],
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          type:'',
          mName:'',
          depId:0,
          wnameSJ:'全部',
          crtTime:'',
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "deptName"
        },
      };
    },
    created() {
      var myDate = new Date();
      var pp =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
      if(pp<9){
        pp = "0"+pp
      }
      // this.queryParams.planMonth = myDate.getFullYear()+'-'+pp;
      console.log('接受页码数据',this.$route.query)
      this.jlPage()
      this.getZhanxin()
      this.search()

    },
    methods: {
      //转换时间戳
      zhuanhuanDate:function(row){
        var oldTime = new Date(row)
        var year=oldTime.getFullYear();
        var month=oldTime.getMonth()+1;
        var date=oldTime.getDate();
        var pp = year+'-'+month+'-'+date
        return  pp
      },
       //记录页码数据
      jlPage () {
      this.localSize = this.$route.query.size
      this.localPage = this.$route.query.page
      console.log(this.$route.query.page)
      if(this.localPage!==undefined) {
          this.queryParams.pageNum = this.localPage
          console.log(111)
      }
      if(this.localSize!==undefined) {
        this.queryParams.pageSize = this.localSize
      }
      },
       //获取站线数据
      getZhanxin:function(){
        request({
          url: 'system/dept/treeselectNoTeam',
          method: 'get',
        }).then(response => {
          this.reportData = response.data
          this.reportData.unshift(
            {deptId:0,deptName:'全部'}
          )
        });
      },
      //战线区队更改
      handleNodeClickSJ:function(node){
        console.log(node,'node')
        this.queryParams.depId = node.deptId
        this.queryParams.wnameSJ = node.deptName
        this.$refs.selectReport.blur()
        console.log(this.queryParams)
        this.search()
      },
      //新增
      cgjhadd:function () {
       
        this.$router.push({path:'/xzhsFY/xzhsFYxg',query:{leixing:this.xzME,page:this.localPage,size:this.localSize}});
      },
      //库存管理返回
      kucunBack:function(row){
        this.kucunShow = false
        console.log('返回数据',row)

      },
      //查询
      search:function(){
        this.loading = true
        this.localPage = this.queryParams.pageNum
        this.localSize = this.queryParams.pageSize
        request({
          url: '/material/reuse/list',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          console.log(this.roleList)
          for (var i=0;i<this.roleList.length;i++){
            if(this.roleList[i].crtTime){
              this.roleList[i].crtTime = this.zhuanhuanDate(this.roleList[i].crtTime)
            }

          }
          this.total = response.total
        });
      },
      //导出
      dcME () {
        this.$confirm('确认导出?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          request({
            url:'material/reuse/export',
            method:'get',
            params:this.queryParams
          }).then((response)=>{
            return this.download(response.data)
          })
        })
      },
      //修改
      handleXG (row) {
       var pp=[
          row=row
       ]
        this.$router.push({path:'/xzhsFY/xzhsFYxg',query:{pp,page:this.localPage,size:this.localSize,leixing:this.xgME}});
      },
      //删除
      handleSC (row) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(()=>{
          console.log(row)
          var scId = row.id
          console.log(scId)
          request({
            url:'material/reuse/'+scId,
            method:'post',
          }).then((response)=>{
             if(response.code=='200'){
               this.search()
               this.$message({
                 type:'success',
                 message:'删除成功'
               })
             }
          })
        })
      },
    }
  };
</script>
